﻿using System;

namespace DotNetDream.Data.Helper
{
    public class OperationStatus
    {
        #region Properties
        public enum Operation
        {
            Insert,
            Update,
            Delete,
            Select
        }

        public bool Succeeded { get; set; }
        public int AffectedRows { get; set; }
        public Operation Action { get; set; }
        public object RecordId { get; set; }
        public string ExceptionMessage { get; set; }
        public string ExceptionInnerMessage { get; set; }
        #endregion

        public OperationStatus()
        {
            //Default as succeeded
            Succeeded = true;
        }

        /// <summary>
        /// Populate the OperationStatus object with fail exception
        /// </summary>
        /// <param name="ex"></param>
        public void FromException(Exception ex)
        {
            Succeeded = false;
            ExceptionMessage = ex.Message;
            if (ex.InnerException != null) ExceptionInnerMessage = ex.InnerException.Message;
        }
    }
}
